package com.fr.chart.plot;

import com.fr.base.Inter;
import com.fr.base.XMLable;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.axis.TextAttr;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.ChartUtils;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Color;
import java.text.Format;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class MeterStyle
  implements XMLable
{
  private static final long serialVersionUID = -7636054199242127287L;
  public static final String XML_TAG = "MeterStyle";
  public static final float DEFAULT_BORDER_SIZE = 3.0F;
  public static final float DEFAULT_CIRCLE_SIZE = 10.0F;
  public static final String CIRCLE = "CIRCLE";
  public static final String PIE = "PIE";
  private String dialShape = "CIRCLE";
  private int meterAngle = 300;
  private double startValue = 0.0D;
  private double endValue = 400.0D;
  private double tickSize = 50.0D;
  private Color tickColor = new Color(47, 46, 46);
  private String units = Inter.getLocText("Unit");
  private Format unitFormat;
  private Color needleColor = new Color(47, 46, 46);
  private Color dialBackgroundColor = new Color(248, 248, 248);
  private boolean tickLabelsVisible = true;
  private TextAttr titleTextAttr = new TextAttr();
  private List intervals;

  public MeterStyle()
  {
    setIntervals(new ArrayList());
    MeterInterval localMeterInterval = new MeterInterval(Inter.getLocText("Chart_Meter_Field") + 1 + "(" + Inter.getLocText("Default") + ")", this.startValue, 3.0D * this.endValue / 8.0D);
    localMeterInterval.setBackgroundColor(new Color(19, 174, 227));
    getIntervals().add(localMeterInterval);
    localMeterInterval = new MeterInterval(Inter.getLocText("Chart_Meter_Field") + 2 + "(" + Inter.getLocText("Default") + ")", 3.0D * this.endValue / 8.0D, 3.0D * this.endValue / 4.0D);
    localMeterInterval.setBackgroundColor(new Color(251, 224, 78));
    getIntervals().add(localMeterInterval);
    localMeterInterval = new MeterInterval(Inter.getLocText("Chart_Meter_Field") + 3 + "(" + Inter.getLocText("Default") + ")", 3.0D * this.endValue / 4.0D, this.endValue);
    localMeterInterval.setBackgroundColor(new Color(228, 108, 138));
    getIntervals().add(localMeterInterval);
  }

  public String getDialShape()
  {
    return this.dialShape;
  }

  public void setDialShape(String paramString)
  {
    this.dialShape = paramString;
  }

  public int getMeterAngle()
  {
    return this.meterAngle;
  }

  public void setMeterAngle(int paramInt)
  {
    this.meterAngle = paramInt;
  }

  public double getStartValue()
  {
    return this.startValue;
  }

  public void setStartValue(double paramDouble)
  {
    this.startValue = paramDouble;
  }

  public double getEndValue()
  {
    return this.endValue;
  }

  public void setEndValue(double paramDouble)
  {
    this.endValue = paramDouble;
  }

  public double getTickSize()
  {
    return this.tickSize;
  }

  public void setTickSize(double paramDouble)
  {
    this.tickSize = paramDouble;
  }

  public Color getTickColor()
  {
    return this.tickColor;
  }

  public void setTickColor(Color paramColor)
  {
    this.tickColor = paramColor;
  }

  public void setDialBackgroundColor(Color paramColor)
  {
    this.dialBackgroundColor = paramColor;
  }

  public Color getDialBackgroundColor()
  {
    return this.dialBackgroundColor;
  }

  public String getUnits()
  {
    return this.units;
  }

  public void setUnits(String paramString)
  {
    this.units = paramString;
  }

  public void setUnitFormat(Format paramFormat)
  {
    this.unitFormat = paramFormat;
  }

  public Format getUnitFormat()
  {
    return this.unitFormat;
  }

  public Color getNeedleColor()
  {
    return this.needleColor;
  }

  public void setNeedleColor(Color paramColor)
  {
    this.needleColor = paramColor;
  }

  public void setTickLabelsVisible(boolean paramBoolean)
  {
    this.tickLabelsVisible = paramBoolean;
  }

  public boolean isTickLabelsVisible()
  {
    return this.tickLabelsVisible;
  }

  public void setTitleTextAttr(TextAttr paramTextAttr)
  {
    this.titleTextAttr = paramTextAttr;
  }

  public TextAttr getTitleTextAttr()
  {
    return this.titleTextAttr;
  }

  public void addInterval(MeterInterval paramMeterInterval)
  {
    getIntervals().add(paramMeterInterval);
  }

  public int getIntervalCount()
  {
    return getIntervals().size();
  }

  public MeterInterval getInterval(int paramInt)
  {
    if ((paramInt < 0) || (paramInt >= getIntervalCount()))
      return null;
    return ((MeterInterval)getIntervals().get(paramInt));
  }

  public void clearAllInterval()
  {
    if (getIntervals() == null)
      return;
    getIntervals().clear();
  }

  public void setIntervals(List paramList)
  {
    this.intervals = paramList;
  }

  public List getIntervals()
  {
    return this.intervals;
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("MeterStyle");
    paramXMLPrintWriter.startTAG("Attr").attr("meterAngle", getMeterAngle()).attr("startValue", getStartValue()).attr("endValue", getEndValue()).attr("tickSize", getTickSize()).attr("tickColor", getTickColor().getRGB()).attr("units", getUnits()).attr("needleColor", getNeedleColor().getRGB()).attr("dialBackgroundColor", getDialBackgroundColor().getRGB()).attr("tickLabelsVisible", isTickLabelsVisible()).attr("dialShape", this.dialShape).end();
    if (getTitleTextAttr() != null)
      getTitleTextAttr().writeXML(paramXMLPrintWriter);
    if (getUnitFormat() != null)
      ReportXMLUtils.writeFormat(paramXMLPrintWriter, this.unitFormat);
    if ((getIntervals() != null) && (getIntervals().size() > 0))
    {
      paramXMLPrintWriter.startTAG("IntervalList");
      int i = 0;
      int j = getIntervals().size();
      while (i < j)
      {
        MeterInterval localMeterInterval = (MeterInterval)getIntervals().get(i);
        localMeterInterval.writeXML(paramXMLPrintWriter);
        ++i;
      }
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if ("Attr".equals(str1))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("meterAngle")) != null)
          setMeterAngle(Integer.valueOf(str2).intValue());
        if ((str2 = paramXMLableReader.getAttr("startValue")) != null)
          setStartValue(Double.valueOf(str2).doubleValue());
        if ((str2 = paramXMLableReader.getAttr("endValue")) != null)
          setEndValue(Double.valueOf(str2).doubleValue());
        if ((str2 = paramXMLableReader.getAttr("tickSize")) != null)
          setTickSize(Double.valueOf(str2).doubleValue());
        if ((str2 = paramXMLableReader.getAttr("tickColor")) != null)
          setTickColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("units")) != null)
          setUnits(str2);
        if ((str2 = paramXMLableReader.getAttr("needleColor")) != null)
          setNeedleColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("dialBackgroudColor")) == null)
          if ((str2 = paramXMLableReader.getAttr("dialBackgroundColor")) == null)
            break label217;
        setDialBackgroundColor(new Color(Integer.parseInt(str2), true));
        if ((str2 = paramXMLableReader.getAttr("tickLabelsVisible")) != null)
          label217: setTickLabelsVisible(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("dialShape")) != null)
          this.dialShape = str2;
      }
      else if ("TextAttr".equals(str1))
      {
        this.titleTextAttr = ((TextAttr)paramXMLableReader.readXMLObject(new TextAttr()));
      }
      else if ("Format".equals(str1))
      {
        this.unitFormat = ReportXMLUtils.readFormat(paramXMLableReader);
      }
      else if ("IntervalList".equals(str1))
      {
        getIntervals().clear();
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final MeterStyle this$0;

          public void readXML()
          {
            if ((paramXMLableReader.isChildNode()) && ("MeterInterval".equals(paramXMLableReader.getTagName())))
              this.this$0.getIntervals().add(paramXMLableReader.readXMLObject(new MeterInterval()));
          }
        });
      }
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    MeterStyle localMeterStyle = (MeterStyle)super.clone();
    if (this.titleTextAttr != null)
      localMeterStyle.titleTextAttr = ((TextAttr)this.titleTextAttr.clone());
    if (this.unitFormat != null)
      localMeterStyle.unitFormat = ((Format)this.unitFormat.clone());
    if (this.intervals != null)
    {
      localMeterStyle.setIntervals(new ArrayList());
      ListIterator localListIterator = getIntervals().listIterator();
      while (localListIterator.hasNext())
        localMeterStyle.getIntervals().add(localListIterator.next());
    }
    return localMeterStyle;
  }

  public boolean equals(Object paramObject)
  {
    int i;
    if (!(paramObject instanceof MeterStyle))
      return false;
    MeterStyle localMeterStyle = (MeterStyle)paramObject;
    if (!(Equals.equals(localMeterStyle.getDialShape(), getDialShape())))
      return false;
    if (localMeterStyle.getStartValue() != getStartValue())
      return false;
    if (localMeterStyle.getEndValue() != getEndValue())
      return false;
    if (localMeterStyle.getMeterAngle() != getMeterAngle())
      return false;
    if (localMeterStyle.getTickSize() != getTickSize())
      return false;
    if (!(Equals.equals(localMeterStyle.getTickColor(), getTickColor())))
      return false;
    if (!(Equals.equals(localMeterStyle.getUnits(), getUnits())))
      return false;
    if (!(Equals.equals(localMeterStyle.getUnitFormat(), getUnitFormat())))
      return false;
    if (!(Equals.equals(localMeterStyle.getNeedleColor(), getNeedleColor())))
      return false;
    if (!(Equals.equals(localMeterStyle.getDialBackgroundColor(), getDialBackgroundColor())))
      return false;
    if (!(Equals.equals(localMeterStyle.getTitleTextAttr(), getTitleTextAttr())))
      return false;
    if (localMeterStyle.isTickLabelsVisible() != isTickLabelsVisible())
      return false;
    if (localMeterStyle.getIntervals() != null)
    {
      if (localMeterStyle.getIntervals().size() != getIntervals().size())
        return false;
      for (i = 0; i < localMeterStyle.getIntervals().size(); ++i)
        if (!(localMeterStyle.getInterval(i).equals(getInterval(i))))
          return false;
    }
    return true;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = new JSONObject();
    localJSONObject.put("startValue", this.startValue);
    localJSONObject.put("endValue", this.endValue);
    localJSONObject.put("meterAngle", this.meterAngle);
    localJSONObject.put("tickSize", this.tickSize);
    localJSONObject.put("dialShape", this.dialShape);
    localJSONObject.put("tickLabelsVisible", this.tickLabelsVisible);
    localJSONObject.put("units", this.units);
    localJSONObject.put("tickColor", ChartUtils.color2JS(this.tickColor));
    localJSONObject.put("dialBackgroundColor", ChartUtils.color2JS(this.dialBackgroundColor));
    localJSONObject.put("needleColor", ChartUtils.color2JS(this.needleColor));
    if (this.unitFormat != null)
      localJSONObject.put("unitFormat", ChartUtils.format2JS(this.unitFormat));
    localJSONObject.put("titleTextAttr", this.titleTextAttr.toJSONObject());
    if ((this.intervals != null) && (this.intervals.size() > 0))
    {
      ArrayList localArrayList = new ArrayList();
      for (int i = 0; i < this.intervals.size(); ++i)
        localArrayList.add(getInterval(i).toJSONObject());
      localJSONObject.put("intervals", localArrayList.toArray());
    }
    return localJSONObject;
  }
}